home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils battery / NiMHSet 0.01 / nimhs001.exe / nimhset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-15  |  2.1 KB  |  107 lines

  1. #include <Pilot.h>                
  2. #ifdef __GNUC__
  3. # include "Callbacks.h"
  4. #endif        
  5.  
  6. #include "resource.h"
  7.  
  8. #include <SysEvtMgr.h>
  9. #include <System/SystemMgr.h>
  10.  
  11. static Err StartApplication(void)
  12. {
  13.    FrmGotoForm(BatBeltForm);
  14.    return 0;
  15. }
  16.  
  17. //static void StopApplication(void)
  18. //{
  19. //}
  20.  
  21. static Boolean MyFormHandleEvent(EventPtr event)
  22. {
  23.    Boolean        handled;
  24.    RectangleType scrollrect,fillrect;
  25.    DirectionType dir;
  26. #ifdef __GNUC__
  27.    CALLBACK_PROLOGUE
  28. #endif
  29.    handled = false;
  30.    switch (event->eType)
  31.      {
  32.       case frmOpenEvent:
  33.     FrmDrawForm(FrmGetActiveForm());
  34.     handled = true;
  35.     break;
  36.      }
  37. #ifdef __GNUC__
  38.    CALLBACK_EPILOGUE
  39. #endif
  40.      return(handled);
  41. }
  42.  
  43. static Boolean ApplicationHandleEvent(EventPtr event)
  44. {
  45.    FormPtr    frm;
  46.    Int        formId;
  47.    Boolean    handled = false;
  48.    
  49.    if (event->eType == frmLoadEvent)
  50.      {
  51.     // Load the form resource specified in the event then activate the form.
  52.     formId = event->data.frmLoad.formID;
  53.     frm = FrmInitForm(formId);
  54.     FrmSetActiveForm(frm);
  55.     
  56.     // Set the event handler for the form.  The handler of the currently 
  57.     // active form is called by FrmDispatchEvent each time it receives an event.
  58.     switch (formId)
  59.       {     
  60.        case BatBeltForm:
  61.          FrmSetEventHandler(frm, MyFormHandleEvent);
  62.          break;
  63.       }
  64.     handled = true;
  65.      }
  66.    
  67.    return handled;
  68. }
  69.  
  70. static void EventLoop(void)
  71. {
  72.    EventType    event;
  73.    Word            error;
  74.    
  75.    do
  76.      {
  77.     EvtGetEvent(&event, evtWaitForever);
  78.     if (! SysHandleEvent(&event))
  79.       if (! MenuHandleEvent(0, &event, &error))
  80.         if (! ApplicationHandleEvent(&event))
  81.           FrmDispatchEvent(&event);
  82.      }
  83.    while (event.eType != appStopEvent);
  84. }
  85.  
  86. DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
  87. {
  88.    Err err = 0;
  89.    UInt warnThres = 226;
  90.    UInt critThres = 160;
  91.    SysBatteryKind batType=sysBatteryKindNiCad;
  92.    switch(cmd)
  93.      {
  94.       case sysAppLaunchCmdNormalLaunch:
  95.     if ((err = StartApplication()) == 0)
  96.       {
  97.          EventLoop();
  98. //         StopApplication();
  99.       }
  100.     break;
  101.       case sysAppLaunchCmdSystemReset:
  102.     SysBatteryInfoV20(1,&warnThres,&critThres,NULL,&batType,NULL);
  103.     break;
  104.      }
  105.    return err;
  106. }
  107.